$(function(){
	let page=1;
	let userName=$(".news-int>p").text();
	/**
	 * 加载分页数据
	 * @param {Object} current
	 */
	let loadData = function(page,newsClassId){
		$.get(
			"news-index1.do","current="+page+"&rowMax=5",
			function(data){
				formatData(data.list);
				formatPage(data);
			},"json"
		);
	}
	let dataCommentDiv = $(".news-list-show-lan").remove();
	/**
	 * 格式化数据
	 * @param {Object} list
	 */
	let formatData = function(list){
		$.each(list,function(i,item){
			var newsContent = item.newsContent;
			var index=newsContent.lastIndexOf("src")
			var a = newsContent.substr(index + 5);
			a = a.substr(0, a.indexOf("\""));

			let div = dataCommentDiv.clone();
			$("._nextPage").before(div);
			div.find(".news-p1").text(item.newsWorker);
			div.find(".news-p2").text(item.newsTime);
		    div.find(".caption-href").text(item.newsTitle);
		    if(index==-1){
		    	div.find(".news-imgs").attr("src", "img/_noimg.png");
		    }
		    else if(a!=null && a != "" && a != undefined){
		    	div.find(".news-imgs").attr("src",a);
			}else{
		    	div.find(".news-imgs").attr("src", "img/_noimg.png");
			}
			div.find(".btn-primary").attr("href","news-show-"+item.newsId+".html");
			div.find(".caption-href").attr("href","news-show-"+item.newsId+".html");
		
		});
		
	}
	/**
	 * 格式化分页按钮
	 * @param {Object} p
	 */
	let formatPage= function(p){
		if(parseInt(p.total)>p.pageSize*page){
			$("._nextPage").attr("style","display:block");
			
		}else{
			$("._nextPage").attr("style","display:none");
			$("._null").attr("style","display:block");
		}
	}
	loadData(page);
	/**
	 * 处理分页事件
	 */
	$("._nextPage").on("click",function(){
		page++;
		loadData(page);
	});
	
})